#!/usr/bin/env  node

const koa=require('koa');
const app=new koa(),
      bp=require('koa-bodyparser'),
      Router=require('koa-router'),//class
      router=new Router,
      log=console.log;


  router.get('/api/tasks/',async (ctx,next)=>{
    let {page,limit}=ctx.query;
    log(ctx.header['user-agent']);
    log(`查询成功,page=${page},limit=${limit}`);
    ctx.body='查询成功';
  })


  router.post('/api/tasks/',async (ctx,next)=>{
    let {task}=ctx.request.body;
    log(`交代办事情列表,task=${task}`);
    ctx.body='添加成功';
  })
  
 router.put('/api/tasks/:id',async ( ctx,next)=>{
   let {task}=ctx.request.body;
   let {id}=ctx.params;
    log(`修改代办事情列表,id=${id},task=${task}`);
    ctx.body='查询成功';
  })
  
 

 router.delete('/api/tasks/:id',async ( ctx,next)=>{ 
   let {id}=ctx.params;
 let {task}=ctx.request.body;
    log(`删除代办事情列表,id=${id},task=${task}`);
    ctx.body='删除成功';
  })

app.use(bp({enableTypes:['json','form','text']}))
app.use(router.routes())

app.listen(8080);
